package profilesettings.data;

import java.util.ArrayList;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;



public class EmailAddressTests implements Runable_Interface {

	private int startSize;

	@Override
	public void run(ArrayList<String> codeInjection, int codeInjectionSize) {
		ArrayList<String> webElements = new ArrayList<String>();
		webElements.add("email");
		webElements.add("password");
		webElements.add("//a[@onclick=\"return openPopup('#email-popup'); \"]");
		webElements.add("(//input[@value='Save'])[2]");
		
		testsAboutMe(webElements, codeInjection, codeInjectionSize);
	}

	private void testsAboutMe(ArrayList<String> webElements,
			ArrayList<String> codeInjection, int codeInjectionSize) {
		for(startSize = 1; startSize < codeInjectionSize; startSize++){
			WebDriver driver = new FirefoxDriver();
			driver.get("https://snapsation.com/login");
			WebElement email = driver.findElement(By.name(webElements.get(0)));
			email.sendKeys("damciodamcio666@gmail.com");
			WebElement password = driver.findElement(By.name(webElements.get(1)));
			password.sendKeys("admin123admin");
			email.submit();
			try {
				Thread.sleep(1800);
			} catch (InterruptedException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS); 
			driver.get("https://www.snapsation.com/settings/");
			WebElement userEmail = driver.findElement(By.xpath(webElements.get(2)));
			userEmail.click();
			WebElement userInput = driver.findElement(By.xpath(webElements.get(3)));
			userInput.sendKeys(codeInjection.get(startSize));
			userInput.submit();
			try {
				Thread.sleep(1800);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
	}

}
